﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TrialManagementTool.Helper
{
    public class UrlHelper
    {
        public static string alterContent(string relativePath)
        {
            Uri contextUri = HttpContext.Current.Request.Url;

            var hostname = contextUri.Host;
            var port = contextUri.Port;
            var scheme = contextUri.Scheme;

            if (hostname.Contains("mobile.dow.com") || hostname.Contains("iis64-root5"))
            {
                return string.Format("{0}://{1}/apps/DASDemoTrial/{2}", scheme, "mobile.dow.com", relativePath);
            }
            else if (hostname.Contains("preview-mobile-dow-com.bsndmz.com") || hostname.Contains("iis64pre-root5"))
            {
                return string.Format("{0}://{1}/apps/DASDemoTrial/{2}", scheme, "preview-mobile-dow-com.bsndmz.com", relativePath);
            }
            else if (hostname == "localhost" && port != 80) //only for local debug
            {
                return string.Format("{0}://{1}:{2}/{3}", scheme, hostname, port, relativePath);
            }
            else
            {
                return string.Format("{0}://{1}/DASDemoTrial/{2}", scheme, hostname, relativePath);
            }
        }

        public static string alterActionLink(string linkText, string action, string controller)
        {
            Uri contextUri = HttpContext.Current.Request.Url;

            var hostname = contextUri.Host;
            var port = contextUri.Port;
            var scheme = contextUri.Scheme;

            if (hostname.Contains("mobile.dow.com") || hostname.Contains("iis64-root5"))
            {
                return string.Format("{0}://{1}/apps/DASDemoTrial/{2}/{3}", scheme, "mobile.dow.com", controller, action);
            }
            else if (hostname.Contains("preview-mobile-dow-com.bsndmz.com") || hostname.Contains("iis64pre-root5"))
            {
                return string.Format("{0}://{1}/apps/DASDemoTrial/{2}/{3}", scheme, "preview-mobile-dow-com.bsndmz.com", controller, action);
            }
            else if (hostname == "localhost" && port != 80) //only for local debug
            {
                return string.Format("{0}://{1}:{4}/{2}/{3}", scheme, hostname, controller, action, port);
            }
            else
            {
                return string.Format("{0}://{1}/DASDemoTrial/{2}/{3}", scheme, hostname, controller, action);
            }

        }
    }
}